﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Reflection;

namespace Fast.Framework
{

    /// <summary>
    /// 动态代理工厂
    /// </summary>
    public static class DynamicProxyFactory
    {

        /// <summary>
        /// 缓存
        /// </summary>
        private static readonly ConcurrentDictionary<string, object> _cache;

        /// <summary>
        /// 构造方法
        /// </summary>
        static DynamicProxyFactory()
        {
            _cache = new ConcurrentDictionary<string, object>();
        }

        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="target">目标</param>
        /// <returns></returns>
        public static DynamicProxy<T> Create<T>()
        {
            var key = typeof(T).GUID.ToString();
            return _cache.GetOrAdd(key, k =>
            {
                return new DynamicProxy<T>();
            }) as DynamicProxy<T>;
        }
    }
}
